package com.easy.goods.controller;

import java.util.HashMap;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.easy.bean.ProductImage;
import com.easy.bean.Products;
import com.easy.common.CommonResult;
import com.easy.goods.service.ProductimageService;

@RestController
public class Productimagec {


        @Autowired
        ProductimageService productimageService;
        //    @RequestMapping(method = RequestMethod.GET, value = "getcategory")
//    public CommonResult getSuperCategoryList() {
//        return CommonResult.success(productSizeService.getSuperCategoryList());
//
//    }
        //分页
//    @RequestMapping(method = RequestMethod.GET, value = "getcategorylist")
//    public CommonResult getCategoryList(Page page, Category category) {
//        return CommonResult.success(productSizeService.getCategoryList(page, category));
//
//    }
        @RequestMapping(method = RequestMethod.GET, value = "getimage")
        public CommonResult getproduct(Products products) {
            List<ProductImage> productsList=   productimageService.list();
            return CommonResult.success(productsList);
        }

        @PostMapping("postimage")
        public CommonResult postproduct(@RequestBody ProductImage productimage) {
            return CommonResult.success(productimageService.save(productimage));
        }
        @PutMapping("updateimage")
        public CommonResult updateproduct(@RequestBody ProductImage productimage) {
            return CommonResult.success(productimageService.updateById(productimage));
        }

        @DeleteMapping("deleteimage/{id}")
        public CommonResult deleteproduct(@PathVariable Integer id) {

            return CommonResult.success(productimageService.deleteproductimage(id));
//        return CommonResult.success(productService.deleteproduct(id));
        }
        //@GetMapping("getcoreproduct")
//    public CommonResult getcoreproduct(@RequestBody Page ,Products products) {
//        Page<Products>  productsPage=new Page<>(page.getPage(),page.getSize());
//        return CommonResult.success(productService.page(page));
//    }
        @GetMapping("imagepage")
        public CommonResult selectPage(Page page, ProductImage productimage) {
            System.out.println(page.getSize() + "-----999" + productimage.getDescription()+"111------"+ page.getCurrent());

            List list = productimageService.list(page, new QueryWrapper<ProductImage>().like("description", productimage.getDescription()));
            long b=productimageService.count();
            System.out.println("总条数"+b);
            System.out.println("--------");
            int a= list.size();
            HashMap map = new HashMap();
            map.put("count",b);
            map.put("list",list);
            return CommonResult.success(map);
        }
//    @PutMapping("sizeshangxiajia/{id}")
//    public void shangxiajia(@PathVariable Integer id) {
//        productSizeService.updatesizeshangxiajia(id);
//    }
//@PostMapping("orderimg")
//public CommonResult orderimg(@RequestParam("file") MultipartFile file){
//    //存储文件
//    String newname= UploadFileUtil.uploadfile(file);
//    //将文件地址存入数据库
//    System.out.println("------");
//    //返回上传文件的地址or返回订单数据
//    System.out.println(EasyConfg.STATIC_PATH+newname);
//    return CommonResult.success(EasyConfg.STATIC_PATH+newname);
//}
//    @PutMapping("orderim")
//    public CommonResult orderimg(@RequestBody Productimage productimage){
//        System.out.println("----------1111");
//        System.out.println(productimage.getImage_url());
//        productimageService.orderimg(productimage);
//        return CommonResult.success(productimage);
//    }

    }


